package com.noah.note.global;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import com.noah.note.utils.AppUtils;
import com.noah.note.utils.LogUtils;

import java.util.Stack;

/**
 * Created by DELL on 2018/5/15.
 */

public class App extends Application {
    private Stack<Activity> activityStack = new Stack<>();//
    @Override
    public void onCreate() {
        super.onCreate();
        AppUtils.initUtils(this);
        registerActivityLifecycleCallbacks(new Application.ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                LogUtils.i("**Created " + activity.getClass().getSimpleName());
                activityStack.add(activity);
            }

            @Override
            public void onActivityStarted(Activity activity) {
                LogUtils.i("**Started " + activity.getClass().getSimpleName());
            }

            @Override
            public void onActivityResumed(Activity activity) {
                LogUtils.i("**Resumed " + activity.getClass().getSimpleName());
            }

            @Override
            public void onActivityPaused(Activity activity) {
                LogUtils.i("**Paused " + activity.getClass().getSimpleName());
            }

            @Override
            public void onActivityStopped(Activity activity) {
                LogUtils.i("**Stopped " + activity.getClass().getSimpleName());
            }

            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

            }

            @Override
            public void onActivityDestroyed(Activity activity) {
                activityStack.remove(activity);
                LogUtils.i("**Destroyed " + activity.getClass().getSimpleName());
                LogUtils.i("activityStack.size = " + activityStack.size());
            }
        });
    }
}
